<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <child :text="content"></child>
    </div>
    <script src="./js/vue.js"></script>
    <script>

        Vue.component('child', {
            inject: ['name'],
            props: {
                text: { 
                    type: Object,
                    default: () => {
                        return {}
                    }
                }
            },
            // $parent.msg 不推荐使用的方法
            template: `
                <div>这是个子组件 {{$parent.msg}} {{text}}</div>
            `,
            created() {
                console.log(this.name)
            },
        })


        new Vue({
            el: '#app',
            provide: { // 适用于高阶组件的父子传值
                name: 'zhangsan'
            },
            data: {
                msg: 'hello world',

                content: {
                    title: '活着'
                }
            }
        })
    </script>
</body>
</html>